<!DOCTYPE html>
<html>
    <head>
        <script>
            function foo1(){
                document.write("foo");
            }
        </script>
    </head>
    <body>
        <script>
            foo1();
        </script>
        <button onclick="foo2()">按钮1</button>
        <a href="javascript:foo1()">链接</a>

        <script>
            function foo2(){
                alert("foo2");
            }
        </script>
    </body>
</html>